// CPPTest.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <Windows.h>
#include <regex>
#include <iostream>

using namespace std::tr1;

bool TestPrime(long number)
{
	for (long i = 2; i*i <= number; i++)
	{
		if (number % i == 0)
			return false;
	}
	return true;
}

long CalPrime(long index)
{
	long currentIndex = 1;
	long currentPrime = 2;

	while (currentIndex < index)
	{
		currentPrime++;
		if (TestPrime(currentPrime))
		{
			currentIndex++;
		}
	}
	return currentPrime;
}

class A : public enable_shared_from_this<A>
{
public:
	
	int a;

	void show()
	{
		//printf("A::show() shared_from_this = %x\n", shared_from_this());
	}

	virtual ~A() {};
};

class B 
{
public:

	int b;
	void show()
	{
		printf("Show B\n");
	}
};

class C : public A, public B, public enable_shared_from_this<C>
{
public:

	int c;
	void show()
	{
		printf("Show C\n");
	}
};

void printraw(A * a)
{
	int sz = sizeof(A) / 4;
	int * inta = (int *) a;
	for(int i = 0; i < sz; i++)
	{
		printf("%X ", inta[i]);
	}

	printf("\n");
}

void invoke(A& a)
{
	a.show();
	printraw(&a);
	printf("a = %d\n\n", (int) &a);
}

class Animal {
public:
	virtual void eat();
};

// Two classes virtually inheriting Animal:
class Mammal : public virtual Animal {
public:
	virtual void breathe();
};

class WingedAnimal : public virtual Animal {
public:
	virtual void flap();
};
 
// A bat is still a winged mammal
class Bat : public Mammal, public WingedAnimal {
};

int _tmain(int argc, _TCHAR* argv[])
{
	printf("Sizeof(Animal): %d\n", sizeof(Animal));
	printf("Sizeof(Mammal): %d\n", sizeof(Mammal));
	printf("Sizeof(WingedAnimal): %d\n", sizeof(WingedAnimal));
	printf("Sizeof(Bat): %d\n", sizeof(Bat));

	getchar();
}